<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="业务日期" prop="operdate">
        <el-date-picker clearable
          v-model="queryParams.operdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择业务日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="域" prop="system">
        <el-select v-model="queryParams.system" placeholder="请选择域" clearable>
          <el-option
            v-for="dict in dict.type.datadomain"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="院区" prop="hostype">
        <el-select v-model="queryParams.hostype" placeholder="请选择院区" clearable>
          <el-option
            v-for="dict in dict.type.hostype"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="指标代码" prop="module">
        <el-input
          v-model="queryParams.module"
          placeholder="请输入指标代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指标编码" prop="qacode">
        <el-input
          v-model="queryParams.qacode"
          placeholder="请输入指标编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运行日期">
        <el-date-picker
          v-model="daterangeLastUpdateDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dataAncher:ancherDailyRpt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dataAncher:ancherDailyRpt:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dataAncher:ancherDailyRpt:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dataAncher:ancherDailyRpt:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ancherDailyRptList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="ID" />
      <el-table-column label="业务日期" align="center" prop="operdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="域" align="center" prop="system">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.datadomain" :value="scope.row.system"/>
        </template>
      </el-table-column>
      <el-table-column label="院区" align="center" prop="hostype">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hostype" :value="scope.row.hostype"/>
        </template>
      </el-table-column>
      <el-table-column label="指标代码" align="center" prop="module" />
      <el-table-column label="指标编码" align="center" prop="qacode" />
      <el-table-column label="指标描述" align="center" prop="desp" />
      <el-table-column label="源数据" align="center" prop="db2value" />
      <el-table-column label="ODS数据" align="center" prop="odsvalue" />
      <el-table-column label="CDR数据" align="center" prop="cdrvalue" />
      <el-table-column label="ODS数据结果" align="center" prop="odsstatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.odsstatus"/>
        </template>
      </el-table-column>
      <el-table-column label="CDR数据结果" align="center" prop="cdrstatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.cdrstatus"/>
        </template>
      </el-table-column>
      <el-table-column label="ODS核对状态" align="center" prop="odschecked">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.data_sync_review_status" :value="scope.row.odschecked"/>
        </template>
      </el-table-column>
      <el-table-column label="CDR核对状态" align="center" prop="cdrchecked">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.data_sync_review_status" :value="scope.row.cdrchecked"/>
        </template>
      </el-table-column>
      <el-table-column label="运行日期" align="center" prop="LastUpdateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.LastUpdateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dataAncher:ancherDailyRpt:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dataAncher:ancherDailyRpt:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改数据指标结果对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="业务日期" prop="operdate">
          <el-date-picker clearable
            v-model="form.operdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择业务日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="域" prop="system">
          <el-select v-model="form.system" placeholder="请选择域">
            <el-option
              v-for="dict in dict.type.datadomain"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="院区" prop="hostype">
          <el-select v-model="form.hostype" placeholder="请选择院区">
            <el-option
              v-for="dict in dict.type.hostype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="指标代码" prop="module">
          <el-input v-model="form.module" placeholder="请输入指标代码" />
        </el-form-item>
        <el-form-item label="指标编码" prop="qacode">
          <el-input v-model="form.qacode" placeholder="请输入指标编码" />
        </el-form-item>
        <el-form-item label="指标描述" prop="desp">
          <el-input v-model="form.desp" placeholder="请输入指标描述" />
        </el-form-item>
        <el-form-item label="源数据" prop="db2value">
          <el-input v-model="form.db2value" placeholder="请输入源数据" />
        </el-form-item>
        <el-form-item label="ODS数据" prop="odsvalue">
          <el-input v-model="form.odsvalue" placeholder="请输入ODS数据" />
        </el-form-item>
        <el-form-item label="CDR数据" prop="cdrvalue">
          <el-input v-model="form.cdrvalue" placeholder="请输入CDR数据" />
        </el-form-item>
        <el-form-item label="ODS数据结果" prop="odsstatus">
          <el-input v-model="form.odsstatus" placeholder="请输入ODS数据结果" />
        </el-form-item>
        <el-form-item label="CDR数据结果" prop="cdrstatus">
          <el-input v-model="form.cdrstatus" placeholder="请输入CDR数据结果" />
        </el-form-item>
        <el-form-item label="ODS核对状态" prop="odschecked">
          <el-radio-group v-model="form.odschecked">
            <el-radio
              v-for="dict in dict.type.data_sync_review_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="CDR核对状态" prop="cdrchecked">
          <el-radio-group v-model="form.cdrchecked">
            <el-radio
              v-for="dict in dict.type.data_sync_review_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="运行日期" prop="LastUpdateDate">
          <el-date-picker clearable
            v-model="form.LastUpdateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择运行日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAncherDailyRpt, getAncherDailyRpt, delAncherDailyRpt, addAncherDailyRpt, updateAncherDailyRpt } from "@/api/dataAncher/ancherDailyRpt";

export default {
  name: "AncherDailyRpt",
  dicts: ['datadomain', 'hostype', 'data_sync_review_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据指标结果表格数据
      ancherDailyRptList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 运行日期时间范围
      daterangeLastUpdateDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        operdate: null,
        system: null,
        hostype: null,
        module: null,
        qacode: null,
        LastUpdateDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        operdate: [
          { required: true, message: "业务日期不能为空", trigger: "blur" }
        ],
        system: [
          { required: true, message: "域不能为空", trigger: "change" }
        ],
        hostype: [
          { required: true, message: "院区不能为空", trigger: "change" }
        ],
        module: [
          { required: true, message: "指标代码不能为空", trigger: "blur" }
        ],
        desp: [
          { required: true, message: "指标描述不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询数据指标结果列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeLastUpdateDate && '' != this.daterangeLastUpdateDate) {
        this.queryParams.params["beginLastUpdateDate"] = this.daterangeLastUpdateDate[0];
        this.queryParams.params["endLastUpdateDate"] = this.daterangeLastUpdateDate[1];
      }
      listAncherDailyRpt(this.queryParams).then(response => {
        this.ancherDailyRptList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        operdate: null,
        system: null,
        hostype: null,
        module: null,
        qacode: null,
        desp: null,
        db2value: null,
        odsvalue: null,
        cdrvalue: null,
        odsstatus: null,
        cdrstatus: null,
        odschecked: null,
        cdrchecked: null,
        LastUpdateDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeLastUpdateDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ID)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据指标结果";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.id || this.ids
      getAncherDailyRpt(ID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据指标结果";
      });
    },
    /** 提交按钮 */
    submitForm() {
      debugger
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAncherDailyRpt(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAncherDailyRpt(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据指标结果编号为"' + IDs + '"的数据项？').then(function() {
        return delAncherDailyRpt(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dataAncher/ancherDailyRpt/export', {
        ...this.queryParams
      }, `ancherDailyRpt_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
